﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessService.Plugin.Helper
{
    /// <summary>
    /// json构造器
    /// </summary>
    public class JsonBuildUtil
    {
        /// <summary>
        /// 生成json数据
        /// </summary>
      public  static void CreateJson(List <dynamic> ipnput)
        {
            //写入JObject
            //创建json字符串根节点
            var obj = new JObject(); //{}
            //Color节点
            obj["Color"] = new JObject();// { "Color" : {} }
            obj["Color"]["Red"] = 0.8;// { "Color" : { "Red" : 0.8  } }
            obj["Color"]["Blue"] = 1.2;// { "Color" : { "Red" : 0.8 , "Blue" : 1.2 } }
            //Category节点
            obj["Category"] = new JObject();// { "Color" : { "Red" : 0.8 , "Blue" : 1.2 }, "Category": {} }
            ////Category->Better数组
            //obj["Category"]["Better"] = new JArray();
            //(obj["Category"]["Better"] as JArray).Add("2121");
            //(obj["Category"]["Better"] as JArray).Add(98);
            //(obj["Category"]["Better"] as JArray).Add(100);
            //(obj["Category"]["Better"] as JArray).Add(96);                     
            //{ "Color" : { "Red" : 0.8 , "Blue" : 1.2 }, "Category": { “Better”： [99, 98, 100, 96] } }
            ////Category->Normal数组
            //obj["Category"]["Normal"] = new JArray();
            //(obj["Category"]["Normal"] as JArray).Add(80);
            //(obj["Category"]["Normal"] as JArray).Add(75);
            //(obj["Category"]["Normal"] as JArray).Add(84);//{ "Color" : { "Red" : 0.8 , "Blue" : 1.2 }, "Category": { “Better”： [99, 98, 100, 96], “Normal”： [80, 75, 84] } }
            ////Category->Bad数组
            //obj["Category"]["Bad"] = new JArray();
            //(obj["Category"]["Bad"] as JArray).Add(JValue.CreateUndefined());
            //(obj["Category"]["Bad"] as JArray).Add(JValue.CreateNull());//{ "Color" : { "Red" : 0.8 , "Blue" : 1.2 }, "Category": { “Better”： [99, 98, 100, 96], “Normal”： [80, 75, 84], "Bad": [ undefined, null ] } }
            //输出json
            var jsonStr = obj.ToString();
        }
    }
}
